﻿<navigation:Page x:Class="Falafel.View.Orders" 
  xmlns:sdk="http://schemas.microsoft.com/winfx/2006/xaml/presentation/sdk" 
  xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
  xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
  xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
  xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
  xmlns:navigation="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls.Navigation"
  xmlns:toolkit="http://schemas.microsoft.com/winfx/2006/xaml/presentation/toolkit" 
  xmlns:controls="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls.DomainServices"
  mc:Ignorable="d" d:DesignWidth="640" d:DesignHeight="480" Style="{StaticResource PageStyle}" >
    
    <Grid x:Name="LayoutRoot">
        <ScrollViewer x:Name="PageScrollViewer" Style="{StaticResource PageScrollViewerStyle}" >

            <Grid x:Name="ContentGrid" Style="{StaticResource ContentGridStyle}">
                <Grid.RowDefinitions>
                    <RowDefinition Height="Auto" />
                    <RowDefinition Height="Auto" />
                    <RowDefinition Height="Auto" />
                    <RowDefinition Height="Auto" />
                    <RowDefinition Height="*" />
                </Grid.RowDefinitions>

                <TextBlock x:Name="HeaderText" Style="{StaticResource HeaderTextStyle}" Grid.Row="0"
                           Text="{Binding Path=ApplicationStrings.OrdersPageTitle, Source={StaticResource ResourceWrapper}}"/>

                <toolkit:BusyIndicator IsBusy="{Binding Source={StaticResource wcGlobal}, Path=ViewModel.IsBusy}" Grid.Row="1" >
                    <sdk:DataGrid ItemsSource="{Binding Source={StaticResource wcGlobal}, Path=ViewModel.DDS.Data}" RowDetailsVisibilityMode="VisibleWhenSelected" 
                              AutoGenerateColumns="False" IsReadOnly="True" Height="170" x:Name="GridOrders" VerticalScrollBarVisibility="Disabled" SelectionMode="Single">
                        <sdk:DataGrid.Columns>
                            <sdk:DataGridTextColumn Binding="{Binding ID}" Header="ID" />
                            <sdk:DataGridTextColumn Binding="{Binding Path=State.Code}" Header="State" />
                            <sdk:DataGridTextColumn Binding="{Binding Total,StringFormat='{}{0:C}'}" Header="Total" />
                            <sdk:DataGridTextColumn Binding="{Binding OrderDate, StringFormat='{}{0:d}'}" Header="Order Dt" />
                            <sdk:DataGridTextColumn Binding="{Binding PurchaseOrderNo}" Header="PO #" />
                            <sdk:DataGridTextColumn Binding="{Binding CreatedUser.Login.UserName}" Header="Created By" />
                            <sdk:DataGridTextColumn Binding="{Binding CreatedDate, StringFormat='{}{0:G}'}" Header="Created On" />
                            <sdk:DataGridTextColumn Binding="{Binding ModifiedUser.Login.UserName}" Header="Modified By" />
                            <sdk:DataGridTextColumn Binding="{Binding ModifiedDate, StringFormat='{}{0:G}'}" Header="Modified On" />
                        </sdk:DataGrid.Columns>
                    </sdk:DataGrid>
                </toolkit:BusyIndicator>

                <sdk:DataPager Grid.Row="2" Source="{Binding Source={StaticResource wcGlobal}, Path=ViewModel.DDS.Data}" x:Name="orderPager"
                               DisplayMode="FirstLastPreviousNextNumeric" IsTotalItemCountFixed="False" PageSize="5" />

                <toolkit:DataForm Grid.Row="3" x:Name="DataFormOrders" ItemsSource="{Binding Source={StaticResource wcGlobal}, Path=ViewModel.DDS.Data}" MinHeight="140" 
                                  AllowDrop="True" AutoEdit="False" AutoCommit="False" AutoGenerateFields="False" CommandButtonsVisibility="None">
                    <toolkit:DataForm.ReadOnlyTemplate>
                        <DataTemplate>
                            <Grid Margin="0" ShowGridLines="False">
                                <Grid.RowDefinitions>
                                    <RowDefinition Height="Auto" />
                                    <RowDefinition Height="Auto" />
                                    <RowDefinition Height="Auto" />
                                    <RowDefinition Height="Auto" />
                                    <RowDefinition Height="*" />
                                </Grid.RowDefinitions>
                                <Grid.ColumnDefinitions>
                                    <ColumnDefinition Width="1*" MinWidth="200" />
                                    <ColumnDefinition Width="2*" />
                                </Grid.ColumnDefinitions>

                                <toolkit:DataField Label="Order ID" Grid.Row="0" Grid.Column="0" Margin="2">
                                    <TextBlock Text="{Binding Path=ID,Mode=OneWay}" />
                                </toolkit:DataField>
                                <toolkit:DataField Label="Total" Grid.Row="0" Grid.Column="1" Margin="2" FontWeight="Bold" HorizontalAlignment="Right">
                                    <TextBlock Text="{Binding Path=Total,Mode=OneWay,StringFormat='{}{0:C}'}" FontWeight="Bold" HorizontalAlignment="Right" />
                                </toolkit:DataField>

                                <toolkit:DataField Label="Modified By" Grid.Row="1" Grid.Column="0" Margin="2">
                                    <TextBlock Text="{Binding Path=ModifiedUser.Login.UserName,Mode=OneWay}" />
                                </toolkit:DataField>
                                <toolkit:DataField Label="Modified On" Grid.Row="1" Grid.Column="1" Margin="2">
                                    <TextBlock Text="{Binding Path=ModifiedDate,Mode=OneWay,StringFormat='{}{0:f}'}" />
                                </toolkit:DataField>

                                <toolkit:DataField Label="Created By" Grid.Row="2" Grid.Column="0" Margin="2">
                                    <TextBlock Text="{Binding Path=CreatedUser.Login.UserName,Mode=OneWay}" />
                                </toolkit:DataField>
                                <toolkit:DataField Label="Created On" Grid.Row="2" Grid.Column="1" Margin="2">
                                    <TextBlock Text="{Binding Path=CreatedDate,Mode=OneWay,StringFormat='{}{0:f}'}" />
                                </toolkit:DataField>

                                <toolkit:DataField Label="State" Grid.Row="3" Grid.Column="0" Margin="2">
                                    <TextBlock Text="{Binding Path=State.Name,Mode=OneWay}" />
                                </toolkit:DataField>
                                <toolkit:DataField Label="Ordered On" Grid.Row="3" Grid.Column="1" Margin="2">
                                    <TextBlock Text="{Binding Path=OrderDate,Mode=OneWay,StringFormat='{}{0:D}'}" />
                                </toolkit:DataField>
                                <toolkit:DataField Label="PO #" Grid.Row="4" Grid.Column="0" Margin="2">
                                    <TextBlock Text="{Binding Path=PurchaseOrderNo,Mode=OneWay,StringFormat='{}{0:D}'}" />
                                </toolkit:DataField>
                            </Grid>
                        </DataTemplate>
                    </toolkit:DataForm.ReadOnlyTemplate>

                    <toolkit:DataForm.EditTemplate>
                        <DataTemplate>
                            <Grid Margin="0" ShowGridLines="False">
                                <Grid.RowDefinitions>
                                    <RowDefinition Height="Auto" />
                                    <RowDefinition Height="Auto" />
                                    <RowDefinition Height="Auto" />
                                    <RowDefinition Height="Auto" />
                                    <RowDefinition Height="*" />
                                </Grid.RowDefinitions>
                                <Grid.ColumnDefinitions>
                                    <ColumnDefinition Width="1*" MinWidth="200" />
                                    <ColumnDefinition Width="2*" />
                                </Grid.ColumnDefinitions>

                                <toolkit:DataField Label="Order ID" Grid.Row="0" Grid.Column="0" Margin="2">
                                    <TextBlock Text="{Binding Path=ID,Mode=OneWay}" />
                                </toolkit:DataField>
                                <toolkit:DataField Label="Total" Grid.Row="0" Grid.Column="1" Margin="2" FontWeight="Bold" HorizontalAlignment="Right">
                                    <TextBox Text="{Binding Path=Total,Mode=TwoWay,StringFormat='{}{0:C}'}" FontWeight="Bold" HorizontalAlignment="Right" MinWidth="100" />
                                </toolkit:DataField>

                                <toolkit:DataField Label="Modified By" Grid.Row="1" Grid.Column="0" Margin="2">
                                    <TextBlock Text="{Binding Path=ModifiedUser.Login.UserName,Mode=OneWay}" />
                                </toolkit:DataField>
                                <toolkit:DataField Label="Modified On" Grid.Row="1" Grid.Column="1" Margin="2">
                                    <TextBlock Text="{Binding Path=ModifiedDate,Mode=OneWay}" />
                                </toolkit:DataField>

                                <toolkit:DataField Label="Created By" Grid.Row="2" Grid.Column="0" Margin="2">
                                    <TextBlock Text="{Binding Path=CreatedUser.Login.UserName,Mode=OneWay}" />
                                </toolkit:DataField>
                                <toolkit:DataField Label="Created On" Grid.Row="2" Grid.Column="1" Margin="2">
                                    <TextBlock Text="{Binding Path=CreatedDate,Mode=OneWay}" />
                                </toolkit:DataField>

                                <toolkit:DataField Label="State" Grid.Row="3" Grid.Column="0" Margin="2">
                                    <ComboBox SelectedValuePath="ID"  DisplayMemberPath="Name"
                                        SelectedItem="{Binding Path=State, Mode=TwoWay}"
                                        ItemsSource="{Binding Source={StaticResource wcGlobal}, Path=ViewModel.Context.States}"/>
                                </toolkit:DataField>
                                <toolkit:DataField Label="Ordered On" Grid.Row="3" Grid.Column="1" Margin="2">
                                    <sdk:DatePicker SelectedDate="{Binding Path=OrderDate,Mode=TwoWay}" MaxWidth="200" HorizontalAlignment="Left" />
                                </toolkit:DataField>
                                <toolkit:DataField Label="PO #" Grid.Row="4" Grid.Column="0" Margin="2">
                                    <TextBox Text="{Binding Path=PurchaseOrderNo,Mode=TwoWay}" />
                                </toolkit:DataField>
                            </Grid>
                        </DataTemplate>
                    </toolkit:DataForm.EditTemplate>
                </toolkit:DataForm>
                
                <StackPanel Grid.Row="4" Orientation="Horizontal" HorizontalAlignment="Right" VerticalAlignment="Top" Margin="0 10">
                    <Button x:Name="CaliforniaButton" Content="Move to California" Margin="4 0" Height="20" Width="120"
                            IsEnabled="{Binding  ElementName=DataFormOrders, Path=Mode, Converter={StaticResource dataFormModeInverseConverter}}" Click="CaliforniaButton_Click" />
                    <Button x:Name="AddButton" Content="Add" Margin="4 0" Height="20" Width="70"
                            IsEnabled="{Binding  ElementName=DataFormOrders, Path=Mode, Converter={StaticResource dataFormModeInverseConverter}}" Click="AddButton_Click" />
                    <Button x:Name="EditButton" Content="Edit" Margin="4 0" Height="20" Width="70"
                            IsEnabled="{Binding  ElementName=DataFormOrders, Path=Mode, Converter={StaticResource dataFormModeInverseConverter}}" Click="EditButton_Click" />
                    <Button x:Name="SaveButton" Content="Save" Margin="4 0" Height="20" Width="70"
                            IsEnabled="{Binding ElementName=DataFormOrders, Path=Mode, Converter={StaticResource dataFormModeConverter}}" Click="SaveButton_Click" />
                    <Button x:Name="CancelButton" Content="Cancel" Margin="4 0" Height="20" Width="70"
                            IsEnabled="{Binding ElementName=DataFormOrders, Path=Mode, Converter={StaticResource dataFormModeConverter}}" Click="CancelButton_Click" />
                </StackPanel>
                
                <StackPanel Grid.Row="4" Orientation="Horizontal" HorizontalAlignment="Left" VerticalAlignment="Top" Margin="0 10">
                    <TextBlock VerticalAlignment="Center" Margin="3 0">Filter price greater than</TextBlock>
                    <TextBox x:Name="TextBoxFilter" MinWidth="75"  KeyUp="TextBoxFilter_KeyUp" Text="0" 
                             IsEnabled="{Binding  ElementName=DataFormOrders, Path=Mode, Converter={StaticResource dataFormModeInverseConverter}}" />
                </StackPanel>
            </Grid>
        </ScrollViewer>
    </Grid>
</navigation:Page>